const express = require('express')
const Engine = require('./engine.js')

module.exports = createServer = () => {
    const app = express()
    app.listen(3001, callback)
    // 跨域设置
    app.all('*', function (req, res, next) {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Content-Type');
        res.header('Access-Control-Allow-Methods', '*');
        res.header('Content-Type', 'application/json;charset=utf-8');
        next();
    });


    app.get('/api/booklist', function (request, response) {
        let engine = new Engine()
        let res = engine.query_all("select * from book", null)
        response.send(res)
        engine.close()
    })


    function callback(msg) {
        console.log(msg)
    }

}
